/*
 * @Author: xuhua
 * @Date: 2023-09-13 16:17:23
 * @LastEditors: xuhua
 * @LastEditTime: 2023-09-19 18:41:09
 * @FilePath: /v3-element-admin/src/router/index.ts
 * @Description:
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
	{
		path: "/redirect/:path(.*)",
		component: Layout,
		meta: { hidden: true, title: "redirect" },
		// component: () => import("@/views/redirect/index.vue"),
		children: [
			{
				path: "/redirect/:path(.*)",
				component: () => import("@/views/redirect/index.vue"),
			},
		],
	},

	{
		path: "/login",
		name: "Login",
		meta: { hidden: true, title: "Login" },
		component: () => import("@/views/login/index.vue"),
	},

	{
		path: "/",
		component: Layout,
		redirect: "/dashboard",
		children: [
			{
				path: "/dashboard",
				component: () => import("@/views/dashboard/index.vue"),
				name: "Dashboard",
				meta: { title: "首页" },
			},
		],
	},
];

// 创建路由
const router = createRouter({
	history: createWebHashHistory(),
	routes: constantRoutes as RouteRecordRaw[],
	// 刷新时,滚动条还原
	scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 重置路由
export function resetRouter() {
	router.replace({ path: "/login" });
}

export default router;
